package org.apache.jsp.admin;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.io.*;
import java.util.*;
import beans.BeanEnlaces;
import mapping.Enlace;
import mapping.UrlEnlace;

public final class modificaenlace_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html; charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			"error/errorpage.jsp", true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write('\n');
      out.write('\n');
      out.write('\n');
      beans.BeanEnlaces mybean = null;
      synchronized (request) {
        mybean = (beans.BeanEnlaces) _jspx_page_context.getAttribute("mybean", PageContext.REQUEST_SCOPE);
        if (mybean == null){
          mybean = new beans.BeanEnlaces();
          _jspx_page_context.setAttribute("mybean", mybean, PageContext.REQUEST_SCOPE);
          out.write('\n');
          out.write('	');
          org.apache.jasper.runtime.JspRuntimeLibrary.introspect(_jspx_page_context.findAttribute("mybean"), request);
          out.write('\n');
        }
      }
      out.write("\n");
      out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n");
      out.write("\n");

	if(session.getAttribute("usuario") == null){
		throw new IllegalArgumentException("Oye! No intentes acceder a esta pagina sin haberte logueado antes.<br/>"+ 
		"Si ya te logueaste es posible que tu sesion haya expirado; en ese caso, vuelve a introducir tu usuario y contrase&ntilde;a");
	}
	else {
		if(!session.getAttribute("es_admin").equals(new Integer(1)))
			throw new IllegalArgumentException("Para acceder a esta pagina debes ser administrador.");
	}

      out.write("\n");
      out.write("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n");
      out.write("<head>\n");
      out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n");
      out.write("<link rel=\"stylesheet\" href=\"../estilos/style.css\" type=\"text/css\" media=\"screen\" charset=\"utf-8\"/>\n");
      out.write("<script src=\"../ajax/scriptaculous-js-1.8.1/lib/prototype.js\" type=\"text/javascript\" charset=\"utf-8\"></script>\n");
      out.write("<script src=\"../ajax/scriptaculous-js-1.8.1/src/effects.js\" type=\"text/javascript\" charset=\"utf-8\"></script>\n");
      out.write("<script src=\"../ajax/ajax_utils.js\" type=\"text/javascript\" charset=\"utf-8\"></script>\n");
      out.write("<script src=\"../ajax/ajax_login.js\" type=\"text/javascript\" charset=\"utf-8\"></script>\n");
      out.write("<script src=\"../js/menu.js\" type=\"text/javascript\" charset=\"utf-8\"></script>\n");
      out.write("<script src=\"../ajax/ajax_enlaces.js\" type=\"text/javascript\" charset=\"utf-8\"></script>\n");
      out.write("<title>ErasmusHelp - Modificaci&oacute;n de enlace</title>\n");
      out.write("</head>\n");
      out.write("<body onload= \"ocultaSubMenu();\">\n");
      out.write("\n");
      out.write("\t");
      org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "hidden_admin.jsp", out, false);
      out.write("\n");
      out.write("\t<div id='page_wrapper'>\n");
      out.write("\t\n");
      out.write("\t");
      org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "cabecera_admin.jsp", out, false);
      out.write('\n');
      out.write('	');
      org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "menu_admin.jsp", out, false);
      out.write("\n");
      out.write("\t\n");
      out.write("\t<div id='content_wrapper'>\n");
      out.write("\t\n");
      out.write("\t<div id = \"contenido\">\n");
      out.write("\t\t<div id=\"wrapper_formmod_enlace\">\n");
      out.write("\t\t");

		mybean.conectar();
		int i = 0;
		String id_enlace = request.getParameter("id_enlace");
		Enlace enl = mybean.getEnlacePorId(id_enlace);
		List listaUrls = enl.getListaUrls();
		
      out.write("\n");
      out.write("\t\t<form action=\"#\" id=\"form_mod_enlace\" onsubmit=\"return false;\">\n");
      out.write("\t\t\t\t<input type=\"hidden\" name=\"numMaxURLS\" id=\"numMaxURLS\" value=\"");
      out.print(listaUrls.size());
      out.write("\" size=\"2\"/>\n");
      out.write("\t\t\t\t<input type=\"hidden\" name=\"numActualURLS\" id=\"numActualURLS\" value=\"");
      out.print(listaUrls.size());
      out.write("\" size=\"2\"/>\t\n");
      out.write("\t\t\t\t<!-- este input almacenara la lista de IDs que han sido eliminados \n");
      out.write("\t\t\t\t\t\tseparados por comas, para posteriormente eliminarlos de la BD -->\n");
      out.write("\t\t\t\t<input type=\"hidden\" name=\"urlsElim\" id=\"urlsElim\" value=\"\"/>\n");
      out.write("\t\t\t\t<input type=\"hidden\" id=\"id_enlace\" name=\"id_enlace\" value=\"");
      out.print(id_enlace);
      out.write("\"/>\n");
      out.write("\t\t\t<fieldset>\n");
      out.write("\t\t\t<legend>Datos de enlace</legend>\n");
      out.write("\t\t\t<br/>\n");
      out.write("\t\t\t<div id=\"itnomenlace\">\n");
      out.write("\t\t\t\t<label for=\"nom_enlace\">Nombre</label>\n");
      out.write("\t\t\t\t<input type=\"text\" name=\"nom_enlace\" id=\"nom_enlace\" value=\"");
      out.print( enl.getEnlace());
      out.write("\" \n");
      out.write("\t\t\t\t\tsize=\"35\" maxlength=\"50\" title=\"Introduzca el nombre del enlace\"/>\n");
      out.write("\t\t\t\t\n");
      out.write("\t\t\t</div>\n");
      out.write("\t\t\t<div id=\"ittipoenlace\">\n");
      out.write("\t\t\t\t<label for=\"tipo_enlace\">Tipo</label>\n");
      out.write("\t\t\t\t<select id=\"tipo_enlace\" name=\"tipo_enlace\" title=\"Seleccione el tipo del enlace\">\n");
      out.write("\t\t\t\t");

					List listaTipoEnlaces = mybean.getTipoEnlaces();
					Iterator it = listaTipoEnlaces.iterator();
					while(it.hasNext()){
						String [] valorTipo = ((String) it.next()).split(",");
						if(valorTipo[1].equals(enl.getTipo_enlace())) { 
      out.write("\n");
      out.write("\t\t\t\t\t\t<option selected=\"selected\" value = \"");
      out.print(valorTipo[0]);
      out.write('"');
      out.write('>');
      out.print(valorTipo[1]);
      out.write("</option>\n");
      out.write("\t\t\t\t");
		} else { 
      out.write(" \t\t\t\t\t\n");
      out.write("\t\t\t\t\t\t<option value = \"");
      out.print(valorTipo[0]);
      out.write('"');
      out.write('>');
      out.print(valorTipo[1]);
      out.write("</option>\n");
      out.write("\t\t\t\t");
		} 
					}//fin while
				
      out.write("\n");
      out.write("\t\t\t\t</select>\n");
      out.write("\t\t\t</div>\n");
      out.write("\t\t\t<br/>\n");
      out.write("\t\t\t<div>\n");
      out.write("\t\t\t\t<div id=\"capabotonesagregaURL\">\n");
      out.write("\t\t\t\t\t<button class=\"mybtn\" onmouseover=\"goLite(this)\" onmouseout=\"goDim(this)\"\n");
      out.write("\t\t\t\t\tonclick=\"agregarOtroURLDescrip()\" title=\"Agregar otra URL\">+</button>\t\t\n");
      out.write("\t\t\t\t\t<button id=\"btnBorrar\" class=\"mybtn\" onmouseover=\"goLite(this)\" onmouseout=\"goDim(this)\"\n");
      out.write("\t\t\t\t\tonclick=\"eliminaFilas()\" disabled=\"disabled\" title=\"Borra URL\">-</button>\t\t\n");
      out.write("\t\t\t\t</div>\t\t\t\n");
      out.write("\t\t\t\t<div id=\"tablaInsercion\">\t\n");
      out.write("\t\t\t\t");

				if(listaUrls != null) {
					Iterator it2 = listaUrls.iterator();
					while(it2.hasNext()) {
						UrlEnlace url = (UrlEnlace) it2.next();
						i++;
					
      out.write("\n");
      out.write("\t\t\t\t\t\t<div class=\"divurl\" id=\"div_url");
      out.print(i);
      out.write("\">\n");
      out.write("\t\t\t\t\t\t\t<!-- se pone un input oculto (aunque todavia no) pq si se le pone al checkbox\n");
      out.write("\t\t\t\t\t\t\t\tel value con el id del url, lo considera nulo pq solo admite valores 0 y 1 -->\n");
      out.write("\t\t\t\t\t\t\t<input type=\"hidden\" id=\"idurl");
      out.print(i);
      out.write("\" name=\"idurl");
      out.print(i);
      out.write("\" size=\"3\" value=\"");
      out.print(url.getId_url_enlace());
      out.write("\"/>\n");
      out.write("\t\t\t\t\t\t\t<input type=\"checkbox\" id=\"chkbox_");
      out.print(i);
      out.write("\" name=\"chkbox_");
      out.print(i);
      out.write("\" class=\"chkbox\" onclick=\"habilitar('btnBorrar')\"/>\n");
      out.write("\t\t\t\t\t\t\t<input type=\"text\" id=\"url");
      out.print(i);
      out.write("\" name=\"url");
      out.print(i);
      out.write("\" value=\"");
      out.print(url.getUrl_enlace());
      out.write("\"\n");
      out.write("\t\t\t\t\t\t\tsize=\"46\" maxlength=\"100\" title=\"Introduzca URL\"/>\n");
      out.write("\t\t\t\t\t\t\t<br/>\n");
      out.write("\t\t\t\t\t\t\t<textarea rows=\"3\" cols=\"35\" id=\"desc");
      out.print(i);
      out.write("\" name=\"desc");
      out.print(i);
      out.write("\" \n");
      out.write("\t\t\t\t\t\t\ttitle=\"Introduza descripci&oacute;n de la URL\">");
      out.print(url.getDescripcion_url());
      out.write("</textarea>\t\t\t\t\t\n");
      out.write("\t\t\t\t\t\t");
if(listaUrls.size() > 1 && i < listaUrls.size()) {
      out.write("\n");
      out.write("\t\t\t\t\t\t\t<hr class=\"separador\"/>\n");
      out.write("\t\t\t\t\t\t");
} // fin if interno
						
      out.write("\n");
      out.write("\t\t\t\t\t\t</div>\n");
      out.write("\t\t\t\t\t");
} // fin while
				} // fin if externo
				
      out.write("\n");
      out.write("\t\t\t\t</div>\n");
      out.write("\t\t\t</div>\n");
      out.write("\t\t\t<div class=\"centrado\">\n");
      out.write("\t\t\t\t<button class=\"mybtn\" onmouseover=\"goLite(this)\" onmouseout=\"goDim(this)\"\n");
      out.write("\t\t\t\tonclick=\"history.back()\" title=\"Cancelar\">Cancelar</button>\n");
      out.write("\t\t\t\t<button class=\"mybtn\" onmouseover=\"goLite(this)\" onmouseout=\"goDim(this)\"\n");
      out.write("\t\t\t\tonclick=\"guarda(");
      out.print(id_enlace);
      out.write("); deshabilitar(this); agregaBarraCarga('res_mod_enlace')\" \n");
      out.write("\t\t\t\ttitle=\"Guardar enlace\">Guardar</button>\n");
      out.write("\t\t\t</div>\n");
      out.write("\t\t\t</fieldset>\n");
      out.write("\t\t</form>\n");
      out.write("\t\t<div class=\"spacer\"></div>\n");
      out.write("\t\t<div id=\"res_mod_enlace\"></div>\n");
      out.write("\t\t<div class=\"spacer\"></div>\n");
      out.write("\t\t</div><!-- fin wrapper_formmod_enlace -->\n");
      out.write("\t");
mybean.desconectar();
      out.write("\n");
      out.write("\t</div><!-- fin contenido -->\n");
      out.write("</div>\n");
      org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "pie.html", out, false);
      out.write("\n");
      out.write("</div>\n");
      out.write("</body>\n");
      out.write("</html>");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
